package com.ruoyi.quartz.task;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.chat.domain.GameFileEntity;
import com.ruoyi.chat.mapper.GameFileMapper;
import com.ruoyi.chat.service.GameFileScanner;
import com.ruoyi.mytool.mapper.IPMachineMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component("gameFileTask")
public class GameFileTask {

    @Autowired
    GameFileMapper gameFileMapper;
    @Autowired
    GameFileScanner gameFileScanner;
    @Autowired
    IPMachineMapper ipMachineMapper;
    public void updateGameIp(String ip) throws InterruptedException, IOException {
        UpdateWrapper<GameFileEntity> updateWrapper = new UpdateWrapper<>();
        String fullUrl;
        if(ip.startsWith("192") || ip.length() > 4){
            fullUrl = "http://" + ip + ":5244";
        }else {
            fullUrl = "http://" + "192.168.1."+ip + ":5244";
        }
        updateWrapper.set("local_prefix", fullUrl);
        updateWrapper.isNotNull("id"); // 确保有where条件
        gameFileMapper.update(null, updateWrapper);
        log.info("更新成功,{}",fullUrl);
    }
}
